/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.global;

import cn.ac.iie.di.bcps.JsonBcpsSender.ClientPool;
import cn.ac.iie.di.tools.Configuration;
import cn.ac.iie.di.tools.JedisConnectionHandler;
import iie.mm.client.ClientAPI;
import java.util.HashMap;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import redis.clients.jedis.Jedis;

/**
 *
 * @author lenovo-pc
 */
public class GlobalParas {

    public static ArrayBlockingQueue<String> newsQueue = new ArrayBlockingQueue(500);
    public static ArrayBlockingQueue<String> ungzipQueue = new ArrayBlockingQueue(500);
    public static ArrayBlockingQueue<String> jsonQueue = new ArrayBlockingQueue(500);
    public static ArrayBlockingQueue<String> retryQueue = new ArrayBlockingQueue(500);

    public static String IP_PORT = null;
    public static String MQ_NEWS = null;

    public static String TYPE_NEWS = null;

    public static String ORI_NEWS = null;
    public static String TMP_NEWS = null;

    public static String DES_NEWS = null;

    public static String FILE_NEWS = null;

    public static String MEDIA_URL = null;
    public static String MEDIA_NAME = null;

    public static int MPPDBSIZE = 3;
    public static String MPPDBUSER = "";
    public static String MPPDBPASSWD = "";
    public static String MPPDBURL = "";
    public static String MPPDBDRIVER = "";
    public static ClientAPI pcInfo = new ClientAPI();

    public static String REDIS_IP = "";
    public static String REDIS_MASTER_NAME = "";
    public static Integer REDIS_DB = null;
    public static JedisConnectionHandler connectionHandler = new JedisConnectionHandler("10.144.32.21:26379;10.144.32.22:26379", "mymaster", 0);

//    public static ClientPool pool;
//    public static Jedis edis = null;
    static {
        try {
            MPPDBUSER = LoadProperties("MPPDBUSER");
            MPPDBPASSWD = LoadProperties("MPPDBPASSWD");
            MPPDBURL = LoadProperties("MPPDBURL");
            MPPDBDRIVER = LoadProperties("MPPDBDRIVER");
            MPPDBSIZE = Integer.valueOf(LoadProperties("MPPDBSIZE"));
            //MQ端口号
            IP_PORT = LoadProperties("IP_PORT");
            //消息队列名称
            MQ_NEWS = LoadProperties("MQ_NEWS");

            //解析字段
            TYPE_NEWS = LoadProperties("TYPE_NEWS");

            //需要解压的文件夹
            ORI_NEWS = LoadProperties("ORI_NEWS");

            //解析文件夹
            TMP_NEWS = LoadProperties("TMP_NEWS");

            //最后存放原始文件的文件夹
            DES_NEWS = LoadProperties("DES_NEWS");

            //不同的文件夹挪走文件处理不一致
            FILE_NEWS = LoadProperties("FILE_NEWS");

//        多媒体
            MEDIA_URL = LoadProperties("MEDIA_URL");
            MEDIA_NAME = LoadProperties("MEDIA_NAME");
            //REDIS
            REDIS_IP = LoadProperties("REDIS_IP");
            REDIS_MASTER_NAME = LoadProperties("REDIS_MASTER_NAME");
            REDIS_DB = Integer.valueOf(LoadProperties("REDIS_DB"));
            //多媒体接口初始化
            pcInfo.init(GlobalParas.MEDIA_URL, GlobalParas.MEDIA_NAME);
//            pool = new ClientPool();
            connectionHandler = new JedisConnectionHandler(REDIS_IP, REDIS_MASTER_NAME, REDIS_DB);
//            JedisConnectionHandler connectionHandler = new JedisConnectionHandler("10.144.32.21:26379;10.144.32.22:26379", "mymaster");

        } catch (Exception ex) {
            Logger.getLogger(GlobalParas.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static String LoadProperties(String str) {
        Configuration conf = Configuration.getConfiguration(ClassLoader.getSystemClassLoader().getResource("config.properties").getFile());
        return conf.getString(str, "");
    }

    public static HashMap<String, Object> Map() {
        HashMap map = new HashMap<String, Object>();
        for (String columntype : GlobalParas.LoadProperties("MAP").split("\\|")) {
            map.put(columntype.split("[:]")[0].toLowerCase(), columntype.split("[:]")[1].toLowerCase());
        }
        return map;
    }
}
